<?php

namespace App\Http\Controllers\Merchant;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Response;

class AuthController extends Controller
{
    public function login(): Response|RedirectResponse
    {
        if(auth()->guard('merchant')->check()){
            return redirect()->route('merchant.dashboard.workplace');
        }
        return $this->inertia('auth/login');
    }

    // 登录
    public function loginSubmit()
    {
        $credentials = request()->validate([
            'email' => 'required|email',
            'password' => 'required',
        ]);
    }

    public function register(): Response
    {
        return $this->inertia('auth/register');
    }

    public function registerSubmit()
    {
        $credentials = request()->validate([
            'email' => 'required|email',
            'password' => 'required',
        ]);
    }

    // 忘记密码
    public function forgetPassword(): Response
    {
        return $this->inertia('auth/forget-password');
    }

    public function forgetPasswordSubmit()
    {
        $credentials = request()->validate([
            'email' => 'required|email',
        ]);
    }

    // 重置密码
    public function resetPassword(): Response
    {
        return $this->inertia('auth/reset-password');
    }

    public function resetPasswordSubmit()
    {
        $credentials = request()->validate([
            'email' => 'required|email',
            'password' => 'required',
        ]);
    }

    // 注销
    public function logout(Request $request): RedirectResponse
    {
        auth()->guard('merchant')->logout();
        $request->session()->invalidate();
        $request->session()->regenerateToken();
        return redirect()->route('merchant.login');
    }
}
